package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.AdvRecommendApplyTbl;
import com.amigo.online.provider.manager.model.entity.AdvRecommendSourceTbl;
import com.amigo.online.provider.manager.model.entity.AdvRecommendVideoTbl;
import com.amigo.online.provider.manager.service.AdvRecommendApplyTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/advRecommendApplyTblController", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AdvRecommendApplyTblController extends BaseController {

    @Resource
    private AdvRecommendApplyTblService advRecommendApplyTblService;

    /**
     * 查询广告申请
     *
     * @param ahat
     * @return
     */
    @PostMapping(value = "/getAdvRecommendApplyTblList")
    public ResponseEntity<Response> getAdvHomeApplyTblList(@RequestBody AdvRecommendApplyTbl ahat) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(ahat.getPageNo(), 10);
        List<AdvRecommendApplyTbl> advRecommendApplyTbl = advRecommendApplyTblService.findAdvRecommendApplyTbl(ahat);

        result.put("advRecommendApplyTbl", advRecommendApplyTbl);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    /**
     * 添加广告申请
     *
     * @param ahat
     * @return
     */
    @PostMapping(value = "/saveAdvRecommendApplyTbl")
    public ResponseEntity<Response> saveAdvAreaTbl(@RequestBody AdvRecommendApplyTbl ahat) {
        return success(advRecommendApplyTblService.saveAdvRecommendApplyTbl(ahat));

    }

    /**
     * 修改广告申请
     *
     * @param ahat
     * @return
     */
    @PutMapping(value = "/updateAdvRecommendApplyTbl")
    public ResponseEntity<Response> updateAdvRecommendApplyTbl(@RequestBody AdvRecommendApplyTbl ahat) {
        return success(advRecommendApplyTblService.updateAdvRecommendApplyTbl(ahat));
    }

    /**
     * 删除广告申请
     *
     * @param ahat
     * @return
     */

    @DeleteMapping(value = "/deleteAdvRecommendApplyTbl")
    public ResponseEntity<Response> deleteAdvRecommendApplyTbl(@RequestBody AdvRecommendApplyTbl ahat) {
        return success(advRecommendApplyTblService.deleteAdvRecommendApplyTbl(ahat));
    }

    /**
     * 获取广告详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/getAdvRecommendApplyTblParticulars")
    public ResponseEntity<Response> getAdvRecommendApplyTblParticulars(Long id) {
        return success(advRecommendApplyTblService.findAdvRecommendApplyTblParticulars(id));
    }

    /**
     * 审核附近广告
     *
     * @param advNearbyApplyTbl
     * @return
     */
    @PostMapping("/check")
    public ResponseEntity<Response> checkHomeApplyAdv(@RequestBody AdvRecommendApplyTbl ahat) {
        boolean re = advRecommendApplyTblService.checkAdv(ahat);
        return success(re);
    }

    /**
     * 添加广告资源
     *
     * @param advNearbySourceTbl
     * @return
     */
    @PostMapping(value = "/addAdvRecommendSourceTbl")
    public ResponseEntity<Response> addAdvRecommendSourceTbl(@RequestBody AdvRecommendSourceTbl ahat) {
        boolean re = advRecommendApplyTblService.saveAdvRecommendSourceTbl(ahat);
        return success(re);
    }

    /**
     * 修改广告资源
     *
     * @param advHomeSourceTbl
     * @return
     */
    @PostMapping(value = "/updateAdvRecommendSourceTbl")
    public ResponseEntity<Response> updateAdvRecommendSourceTbl(@RequestBody AdvRecommendSourceTbl ahat) {
        boolean re = advRecommendApplyTblService.updateAdvRecommendSourceTbl(ahat);
        return success(re);
    }

    /**
     * 添加热门广告资源 AdvRecommendVideoTbl
     *
     * @param arvt
     * @return
     */
    @PostMapping(value = "/saveAdvRecommendVideoTbl")
    public ResponseEntity<Response> saveAdvRecommendVideoTbl(@RequestBody AdvRecommendVideoTbl arvt) {

        boolean re = advRecommendApplyTblService.saveAdvRecommendVideoTbl(arvt);
        return success(re);
    }


    @PutMapping(value = "/updateAdvRecommendVideoTbl")
    public ResponseEntity<Response> updateAdvRecommendVideoTbl(@RequestBody AdvRecommendVideoTbl arvt) {
        return success(advRecommendApplyTblService.updateAdvRecommendVideoTbl(arvt));
    }

    @PutMapping(value = "/deleteAdvRecommendVideoTbl")
    public ResponseEntity<Response> deleteAdvRecommendVideoTbl(@RequestBody AdvRecommendVideoTbl arvt) {
        return success(advRecommendApplyTblService.deleteAdvRecommendVideoTbl(arvt));
    }


}
